package com.sfh.base.ui;

import android.support.annotation.IdRes;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.View;

import com.sfh.base.mvp.IView;
import com.sfh.base.ui.dialog.IAlertTemple;

/**
 * 功能描述:MVP【不存在任何业务逻辑代码】
 *
 * @date 2017/7/5
 */
abstract class UIStyleFragment extends Fragment implements IView {

    public String getName() {

        return "";
    }

    @Override
    public void showLoading(String message, boolean cancelAble, boolean... isBgColor) {

        FragmentActivity activity = getActivity ();
        if (activity == null || activity.isFinishing () || !(activity instanceof UIStyleActivity)) {
            return;
        }
        ((UIStyleActivity) activity).showLoading (message, cancelAble, isBgColor);
    }

    public <T extends View> T $(View view, @IdRes int resId) {

        return (T) view.findViewById (resId);
    }

    @Override
    public void hideLoading() {

        FragmentActivity activity = getActivity ();
        if (activity == null || activity.isFinishing () || !(activity instanceof UIStyleActivity)) {
            return;
        }
        ((UIStyleActivity) activity).hideLoading ();
    }

    @Override
    public void showDialog(IAlertTemple alert, boolean cancelAble) {

        FragmentActivity activity = getActivity ();
        if (activity == null || activity.isFinishing () || !(activity instanceof UIStyleActivity)) {
            return;
        }
        ((UIStyleActivity) activity).showDialog (alert, cancelAble);
    }

    @Override
    public void hideDialog() {

        FragmentActivity activity = getActivity ();
        if (activity == null || activity.isFinishing () || !(activity instanceof UIStyleActivity)) {
            return;
        }
        ((UIStyleActivity) activity).hideDialog ();
    }

    @Override
    public void showToast(String message, int ms, int... gravity) {

        FragmentActivity activity = getActivity ();
        if (activity == null || activity.isFinishing () || !(activity instanceof UIStyleActivity)) {
            return;
        }
        ((UIStyleActivity) activity).showToast (message, ms, gravity);
    }


}
